package com.jf3q.common.handler;

import com.jf3q.common.vo.ResultVo;
import com.jf3q.common.exception.JfException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author:xiaojie
 * @create: 2023-04-25 09:32
 * @Description:
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    //指定出现什么异常执行这个方法
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody //为了返回数据
    public ResultVo error(RuntimeException e) {
        e.printStackTrace();
        return ResultVo.error(e.getMessage());
    }



    /**
     * 自定义异常
     */
    @ExceptionHandler(JfException.class)
    @ResponseBody //为了返回数据
    public ResultVo error(JfException e) {
        e.printStackTrace();
        return ResultVo.error(e.getCode(),e.getMsg());
    }
}
